/**
 * Basic header/include file for MouseHelper.cpp.
 *
 * @author GabuEx, dawnmew
 * @since 1.0
 *
 * Licensed under the MIT License.
 *
 * Copyright (c) 2012 Equestrian Dreamers
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifndef MOUSEHELPER_H
#define MOUSEHELPER_H

#include <SDL2/SDL.h>

#include "Rectangle.h"
#include "Vector2.h"

#include <map>
#include <vector>

using namespace std;

class MouseHelper
{
public:
    static void Init();
    static void UpdateState(bool isLeftButtonDown, int mouseX, int mouseY, bool drawCursor);
    static void UpdateTiming();

    static bool MouseOverRect(RectangleWH rectangle);
    static bool MouseDownOnRect(RectangleWH rectangle);

    static bool PressedAndHeldAnywhere();
    static bool DoublePressedAndHeldAnywhere();

    static bool ClickedOnRect(RectangleWH rectangle);
    static bool ClickedAnywhere();
    static bool DoubleClickedOnRect(RectangleWH rectangle);
    static bool DoubleClickedAnywhere();

    static Vector2 GetMousePosition();

    static void HandleClick();
    static void HandleDoubleClick();

    static bool GetDrawCursor() { return MouseHelper::drawCursor; }

private:
    static bool IsMouseInRect(RectangleWH rectangle);
    static bool IsMouseInViewport();

    static bool clickPossible;
    static bool doubleClickPossible;
    static bool doubleClickWasPossible;
    static bool clicked;
    static bool doubleClicked;
    static bool previousWasLeftButtonDown;
    static Vector2 previousMousePosition;
    static bool drawCursor;

    static Uint32 initialLeftButtonDownTime;
    static Vector2 initialLeftButtonDownPosition;
    static Uint32 initialClickTime;
};

#endif
